#light
namespace PresFirst.Tests
#r "PresFirst.dll"
#r "nunit.framework.dll"
#r "Rhino.Mocks.dll"
open NUnit.Framework
open Rhino.Mocks
open Rhino.Mocks.Constraints
open PresFirst
open System

[<TestFixture>]
type NewFibPresenter() =
    let mutable mocks = new MockRepository()
    let mock<'T> = mocks.CreateMock<'T>(null)
    
    [<SetUp>]
    member x.TestSetUp() =
        mocks <- new MockRepository()

    [<TearDown>]
    member x.TestTearDown() =
        mocks.VerifyAll()
        
    member x.Replay() =
        mocks.ReplayAll()

    [<Test>]
    member x.SetsTitle() =
        let m = mock<IFibModel>
        let v = mock<IFibView>
        
        let _, (event : IEvent<EventArgs>) = IEvent.create()
        SetupResult.For(v.get_Calculating()).Return(event) |> ignore
        v.Title <- "title"
        x.Replay()
        
        new FibPresenter(m, v) |> ignore

    [<Test>]
    member x.OnCalculatingGetsResultAndDisplaysInView() =
        let m = mock<IFibModel>
        let v = mock<IFibView>
        
        let trigger, (event : IEvent<EventArgs>) = IEvent.create()
        SetupResult.For(v.get_Calculating()).Return(event) |> ignore
        v.Title <- "title"
        Expect.Call(v.NumberToCalculate).Return("4") |> ignore
        Expect.Call(m.Calculate(4)).Return(3) |> ignore
        v.DisplayResult("3")
        x.Replay()
        
        new FibPresenter(m, v) |> ignore
        trigger(new EventArgs())
